<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>fire 方法用于手动触发指定事</title>
  <script src="./konva.min.js"></script>
</head>

<body>
  <h1>fire 方法用于手动触发指定事</h1>
  <hr>
  <div id="container"></div>
</body>

</html>
<script>
  // 创建舞台和图层
  var stage = new Konva.Stage({
    container: 'container',
    width: 500,
    height: 500
  })

  var layer = new Konva.Layer()

  // 创建一个矩形
  var rect = new Konva.Rect({
    x: 100,
    y: 100,
    width: 100,
    height: 100,
    fill: 'red'
  })
  layer.add(rect)

  // 监听矩形的点击事件
  rect.on('click', function () {
    console.log('Rectangle clicked')
  })

  // 手动触发矩形的点击事件
  rect.fire('click')
  stage.add(layer)

</script>